package com.example.wifimonitor.com.hanj;

import cn.hutool.core.util.URLUtil;

import java.util.ArrayList;

/**
 * @author hanj.cn@outlook.com
 */
public class Judge {

    private static User[] users = {new User("我", "我的se2"), new User("father", "爸爸的vivoS7"), new User("mother", "妈妈的OPPOA5")};

    public static void isOnline(User user, ArrayList<String> hostList) {

        // 我的se2 = "%E6%88%91%E7%9A%84se2"
        if (hostList.contains(URLUtil.encode(user.getDeviceName()))) {

            // 如果上次在线则不发通知
            if (!user.isOnline()) {

                // 在线状态改变
                user.setOnline(true);

                System.out.println(user.getDeviceName() + "上线了");

                // 发送通知
                SendMessage.sendMsgToBark(URLUtil.encode(user.getUsername()), URLUtil.encode("⭐" + user.getDeviceName() + "上线了"), URLUtil.encode("上线时间:" + MyUtils.getTime() + "\n上次在线:" + user.getTime()), null);

                // 记录时间
                user.setTime(MyUtils.getTime());

            }
        } else if (user.isOnline()) {

            // 重置在线状态
            user.setOnline(false);

            System.out.println(user.getDeviceName() + "已下线");

            // 发送通知
            SendMessage.sendMsgToBark(URLUtil.encode(user.getUsername()), URLUtil.encode("❗" + user.getDeviceName() + "已下线"), URLUtil.encode("下线时间:" + MyUtils.getTime() + "\n上次在线:" + user.getTime()), null);
        }
    }

    public static User[] getUsers() {

        return users;
    }

}
